// 定时任务路由
import { Router } from 'express';
import jobController from '@/controllers/monitor/job.controller';
import { authMiddleware } from "@/middlewares/auth.middleware";
import { permissionMiddleware } from "@/middlewares/permission.middleware";
import { validateJobCreate, validateJobUpdate, validateJobChangeStatus, validateJobRun, validateJobRemove, validateJobDetail } from '@/validators/monitor/job.validator';

const router = Router();

/**
 * 定时任务监控路由
 * 路径前缀：/monitor/job
 */

// ================== 定时任务相关 ==================

// 所有路由均需认证
router.use(authMiddleware);

// 查询定时任务列表
router.get('/list', permissionMiddleware('monitor:job:list'), jobController.list);

// 新增定时任务
router.post('/', permissionMiddleware('monitor:job:add'), validateJobCreate, jobController.add);

// 定时任务状态修改
router.put('/changeStatus', permissionMiddleware('monitor:job:changeStatus'), validateJobChangeStatus, jobController.changeStatus);

// 定时任务立即执行一次
router.put('/run', permissionMiddleware('monitor:job:changeStatus'), validateJobRun, jobController.run);

// 修改定时任务
router.put('/', permissionMiddleware('monitor:job:edit'), validateJobUpdate, jobController.edit);

// 获取定时任务详细信息
router.get('/:jobId', permissionMiddleware('monitor:job:query'), validateJobDetail, jobController.getInfo);

// 删除定时任务
router.delete('/:jobIds', permissionMiddleware('monitor:job:remove'), validateJobRemove, jobController.remove);

// 导出定时任务
router.post('/export', permissionMiddleware('monitor:job:export'), jobController.export);

export default router; 